
import { appId } from '../utils/config'
import { CuleProps } from '../utils/type'
import { http as axios } from './request'

//获取图片地址
export const fileUrl = (key: string) => {
  return axios({
    method: 'GET',
    url: '/api/system/file/url',
    params: { key }
  })
}

//获取当前坐标
export const ipLocation = (ip: string) => {
  return axios({
    method: 'GET',
    url: '/api/system/lbs/ipLocation',
    params: { ip }
  })
}

export const regionList = (id: string) => {
  return axios({
    method: 'GET',
    url: '/api/system/lbs/districtChildren',
    params: { id }
  })
}

/**
 * 通过坐标获取区id
 * @param lat
 * @param lng
 * @returns
 */
export const reverseGeocoder = (lat: number, lng: number) => {
  return axios({
    method: 'GET',
    url: '/api/system/lbs/reverseGeocoder',
    params: { lat, lng }
  })
}

/**
 *
 * @param file     file的文件
 * @param dirType  类型为：class|school|coach|train_site 不传默认进入other
 * @returns
 */
// export const uploadByFile = (file: File, dirType: string) => {
//     const fileFormData = new FormData()
//     fileFormData.append('file', file)
//     fileFormData.append('dirType', dirType)
//     return axios({
//         method: 'POST',
//         url: '/api/system/file/upload',
//         data: fileFormData
//     })
// }

/**
 *
 * @param fileStr  base64的文件
 * @param dirType  类型为：class|school|coach|train_site 不传默认进入other
 * @returns
 */
export const uploadByBase64 = (fileStr: string, dirType?: string) => {
  return axios({
    method: 'POST',
    url: '/api/system/file/upload/base64',
    data: { fileStr, dirType }
  })
}

//获取客服地址
export const serviceUrl = () => {
  return axios({
    method: 'GET',
    url: '/api/user/wxcp/getCustomerUrl'
  })
}

//获取apptoken
export const getAppToken = () => {
  return axios({
    method: 'POST',
    url: '/api/user/admin/app-token',
    data: { appId: appId, appSecret: '20240507175722ubgjmi7elgz5e6nrhjmchy' }
  })
}

//更新线索
export const updateCule = (data: CuleProps) => {
  return axios({
    method: 'PUT',
    url: '/api/system/external/clues',
    data
  })
}

//获取所有的字典 dictType 1 后台 2 小程序
export const dictAll = (dictType = 2) => {
  return axios({
    method: 'GET',
    url: '/api/system/dictItem/all',
    params: { dictType }
  })
}
